package swordoffer.offer54;

import swordoffer.offer18.LeetCode;

public class RecursionSolutionDebug {
    int cnt = 0;
    int res = 0;
    int flag = 0;
    public int kthLargest(TreeNode root, int k) {
        return dfs(root, k);
    }
    public int dfs(TreeNode root, int k){
        if(root == null){
            return 0;
        }
        if(flag == 1){
            return res;
        }
        dfs(root.right, k);
        cnt++;
        if(cnt == k){
            res = root.val;
            flag = 1;
        }
        dfs(root.left, k);
        return res;
    }
    public static void main(String[] args) {
        TreeNode root = new TreeNode(5);
        root.left = new TreeNode(3);
        root.right = new TreeNode(6);
        root.left.left = new TreeNode(2);
        root.left.right = new TreeNode(4);
        root.left.left.left = new TreeNode(1);
        new RecursionSolutionDebug().kthLargest(root,2);
    }
}
